import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:ytbusiness/config/style.dart';
import 'package:ytbusiness/models/notify_list_model.dart';
import 'package:ytbusiness/page/message_notice/notify_home/notify_page/notify_view_model.dart';
import 'package:ytbusiness/state/provider_widget.dart';
import 'package:ytbusiness/state/user_role.dart';
import 'package:ytbusiness/utils/screen_adaptation.dart';
import 'package:ytbusiness/widgets/simple_widget.dart';

///通知
class Notify extends StatefulWidget {
  @override
  _NotifyState createState() => _NotifyState();
}

class _NotifyState extends State<Notify> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: YTStyle.bgColor,
      body: ProviderWidget<NotifyViewModel>(
        onReady: (model) {
          model.getNotify(
            context,
            data: {
              "role_id": Provider.of<UserRole>(context, listen: false).role
            },
          );
        },
        builder: (context, model, child) {
          return simpleRefresh(
            onRefresh: () => model.onRefresh(context: context),
            onLoad: () => model.onLoad(),
            child: ListView.builder(
                shrinkWrap: true,
                itemCount: model?.notifyList?.length ?? 0,
                itemBuilder: (context, index) {
                  if (model?.notifyList[index]?.noticeType == "1" ||
                      model?.notifyList[index]?.noticeType == "3") {
                    return _imageItem(model?.notifyList[index]);
                  } else {
                    return _textItem();
                  }
                }),
          );
        },
        model: NotifyViewModel(Provider.of(context)),
      ),
    );
  }

  //文本
  Widget _textItem() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        Container(
          margin: EdgeInsets.only(
              left: setWidth(15), top: setWidth(12), right: setWidth(15)),
          decoration: BoxDecoration(
              color: Colors.white, borderRadius: BorderRadius.circular(8)),
          padding: EdgeInsets.all(setWidth(15)),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Row(
                children: [
                  Container(
                    child: Image.asset(
                      "assets/images/notify_list.png",
                      fit: BoxFit.cover,
                    ),
                    width: setWidth(38),
                    height: setWidth(38),
                  ),
                  SizedBox(
                    width: setWidth(14),
                  ),
                  Container(
                    child: Text(
                      "系统消息",
                      style: TextStyle(
                          color: Color(0xff000000), fontSize: setSp(15)),
                    ),
                  ),
                ],
              ),
              SizedBox(
                height: setWidth(15),
              ),
              Container(
                height: setWidth(0.5),
                color: Color(0xffF0F0F0),
              ),
              SizedBox(
                height: setWidth(15),
              ),
              Container(
                child: Text(
                  "系统通知，恭喜你的留言想那日束发从军,想那日霜角辕 门想那日挟剑惊风，想那日横槊凌云。"
                  "帐前旗,腰后印， 桃花马衣柳叶惊穿胡阵，想那日横槊凌云。帐前旗腰后 印桃马衣柳叶，惊穿胡阵。",
                  maxLines: 4,
                  overflow: TextOverflow.ellipsis,
                ),
              ),
              SizedBox(
                height: setWidth(21),
              ),
              Container(
                height: setWidth(0.5),
                color: Color(0xffF0F0F0),
              ),
              SizedBox(
                height: setWidth(13.5),
              ),
              Container(
                child: Text(
                  "详情",
                  style:
                      TextStyle(color: Color(0xff4D90FF), fontSize: setSp(13)),
                ),
              ),
            ],
          ),
        ),
        Container(
          margin: EdgeInsets.only(top: setWidth(20), bottom: setWidth(10)),
          padding: EdgeInsets.only(
              left: setWidth(9),
              top: setWidth(5),
              right: setWidth(9),
              bottom: setWidth(5)),
          decoration: BoxDecoration(
              color: Color.fromARGB(25, 0, 0, 0),
              borderRadius: BorderRadius.circular(4)),
          child: Text(
            "11月24日 下午13:15",
            style: TextStyle(color: Color(0xffFFFFFF), fontSize: setSp(11)),
          ),
        ),
      ],
    );
  }

  //图文
  Widget _imageItem(NotifyItem item) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        Container(
          margin: EdgeInsets.only(
              left: setWidth(15), top: setWidth(12), right: setWidth(15)),
          decoration: BoxDecoration(
              color: Colors.white, borderRadius: BorderRadius.circular(8)),
          padding: EdgeInsets.only(top: setWidth(15), bottom: setWidth(15)),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                padding:
                    EdgeInsets.only(left: setWidth(15), right: setWidth(15)),
                child: Row(
                  children: [
                    Container(
                      child: Image.asset(
                        "assets/images/notify_list.png",
                        fit: BoxFit.cover,
                      ),
                      width: setWidth(38),
                      height: setWidth(38),
                    ),
                    SizedBox(
                      width: setWidth(14),
                    ),
                    Container(
                      child: Text(
                        "系统消息",
                        style: TextStyle(
                            color: Color(0xff000000), fontSize: setSp(15)),
                      ),
                    ),
                  ],
                ),
              ),
              SizedBox(
                height: setWidth(15),
              ),
              Container(
                margin:
                    EdgeInsets.only(left: setWidth(15), right: setWidth(15)),
                height: setWidth(0.5),
                color: Color(0xffF0F0F0),
              ),
              SizedBox(
                height: setWidth(15),
              ),
              Container(
                child: Image.network(
                  "${item?.noticeImg}",
                  fit: BoxFit.cover,
                ),
              ),
              SizedBox(
                height: setWidth(5),
              ),
              Container(
                padding:
                    EdgeInsets.only(left: setWidth(15), right: setWidth(15)),
                child: Text(
                  item?.noticeName ?? "",
                  maxLines: 4,
                  overflow: TextOverflow.ellipsis,
                ),
              ),
              SizedBox(
                height: setWidth(21),
              ),
              Container(
                height: setWidth(0.5),
                color: Color(0xffF0F0F0),
              ),
              SizedBox(
                height: setWidth(13.5),
              ),
              Container(
                padding:
                    EdgeInsets.only(left: setWidth(15), right: setWidth(15)),
                child: Text(
                  "详情",
                  style:
                      TextStyle(color: Color(0xff4D90FF), fontSize: setSp(13)),
                ),
              ),
            ],
          ),
        ),
        Container(
          margin: EdgeInsets.only(top: setWidth(20), bottom: setWidth(10)),
          padding: EdgeInsets.only(
              left: setWidth(9),
              top: setWidth(5),
              right: setWidth(9),
              bottom: setWidth(5)),
          decoration: BoxDecoration(
              color: Color.fromARGB(25, 0, 0, 0),
              borderRadius: BorderRadius.circular(4)),
          child: Text(
            "11月24日 下午13:15",
            style: TextStyle(color: Color(0xffFFFFFF), fontSize: setSp(11)),
          ),
        ),
      ],
    );
  }
}
